/**
 * 
 */
package lt.inkredibl.iit;

import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.util.Iterator;
import java.util.List;

public class ContourIterable
	implements Iterable<Line2D.Double>
{
	private List<Point2D> _points;
	
	public ContourIterable(List<Point2D> points)
	{
		_points = points;
	}
	
	public Iterator<Line2D.Double> iterator()
	{
		return new Iterator<Line2D.Double>()
		{
			private int _i = 0;

			public boolean hasNext()
			{
				return _points.size() > _i;
			}

			public Line2D.Double next()
			{
				if (hasNext())
				{
					_i++;
				}
				else
				{
					return null;
				}

				if (_points.size() > _i)
				{
					return new Line2D.Double(_points.get(_i - 1).getX(), _points.get(_i - 1).getY(), _points.get(_i).getX(), _points.get(_i).getY());
				}
				else
				{
					return new Line2D.Double(_points.get(_points.size() - 1).getX(), _points.get(_points.size() - 1).getY(), _points.get(0).getX(), _points.get(0).getY());
				}
			}

			public void remove()
			{
				throw new UnsupportedOperationException();
			}

		};
	}

	public List<Point2D> getPoints()
	{
		return _points;
	}
}